Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tileset tab in examples #46

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Conversation

juandjara
Copy link

No description provided.

@donmccurdy
Copy link
Member

@juandjara is this ready for review? I see you've assigned us as reviewers, but it's still marked as a draft and CI is not yet passing, so I'm removing this from my review list for now - please feel free to update the PR and re-assign me whenever you're ready!

@donmccurdy donmccurdy removed their request for review January 29, 2025 15:42
Comment on lines 99 to 112
onViewportLoad(tiles) {
data?.then((res) => {
setTilesLoaded(true)
res.widgetSource.loadTiles(tiles)
const bbox = new WebMercatorViewport(viewState).getBounds()
const spatialFilter = createViewportSpatialFilter(bbox)
if (spatialFilter) {
res.widgetSource.extractTileFeatures({ spatialFilter })
}
})
},
}),
];
}, [data, layerVisibility]);
Copy link
Member

@donmccurdy donmccurdy Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a useMemo dependency for viewState here – the tiles may be filtered by an old viewport, returning incorrect or missing data.

The other thing to consider is that the 'onViewportLoad' event could happen either before or after the (debounced) 'onViewStateChange' event, when the user moves the map. If 'onViewportLoad' is second, then there is nothing that cues the widgets to recalculate, and they'll keep showing old results.

We could fix that by adding an imperative .refresh() method to the widgets, but that feels like "bad style" in React... maybe the simplest thing is just to force-update the viewState once more, after tiles load? Then we can remove the extractTileFeatures call here, and most of the time avoid filtering twice:

onViewportLoad(tiles) {
  data?.then((res) => {
    setTilesLoaded(true);
    res.widgetSource.loadTiles(tiles);
    setViewState({ ...viewState }); // force refresh
  });
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This fixes it!
I think the initial using of data.then everywhere is what threw me off when reading the async flows as I just copied that from other examples. But this seems to work so great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants